import time
from iotdb.Session import Session
from iotdb.utils.IoTDBConstants import TSDataType, TSEncoding, Compressor


# 初始化
session = Session(
    host="47.122.63.169",
    port="6667",
    user="root",
    password="root",
    fetch_size=1024,
    zone_id="UTC+8",
)

# 打开连接
session.open(False)

# 插入数据
session.insert_record(
    device_id="root.test.test", 
    timestamp=int(time.time()*1000), 
    measurements=["status"], 
    data_types=[TSDataType.DOUBLE],
    values=[0.1])

# 查询数据
result = session.execute_query_statement("select status from root.test.test order by time desc")
while result.has_next():
    print(result.next())

# 关闭连接
session.close()